<template>
  <a-card :bordered="false">

    <!-- 详情列表 -->

    <template>
      <a-descriptions :title="bookdetail.bookletName">

        <a-descriptions-item label="商品册总成本(元)">
          {{ bookdetail.allPrice }}
        </a-descriptions-item>
        <a-descriptions-item label="商品册售价(元/册)">
          {{ bookdetail.price }}
        </a-descriptions-item>
        <a-descriptions-item label="总共(册)">
          {{ Number(bookdetail.residueNum) + Number(bookdetail.issueNum) }}
        </a-descriptions-item>
        <a-descriptions-item label="剩余">
          {{ bookdetail.residueNum }}册
        </a-descriptions-item>

      </a-descriptions>
      <a-button @click="setyuejiewindow" type="primary"
                style="color: #F9D532;width: 80px;height: 36px;background: #333333;border-style: none;">
        新增发放
      </a-button>
    </template>
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">

          <!--          <a-col :md="4" :sm="12">
                      <a-form-item label="面料编号">
                        <a-input placeholder="请输入面料编号" v-model="queryParam.fabricCode"></a-input>
                      </a-form-item>
                    </a-col>

                    <a-col :md="4" :sm="12">
                      <a-form-item label="供应商">
                        <a-input placeholder="请输入供应商编号" v-model="queryParam.gysCode" style="width: 100%"></a-input>
                      </a-form-item>
                    </a-col>

                    <a-col :md="4" :sm="12">
                      <a-form-item label="销售状态">
                        <a-select placeholder="请选择销售状态" style="width: 100%" v-model="queryParam.status">
                          <a-select-option value="0">
                            上架中
                          </a-select-option>
                          <a-select-option value="2">
                            已下架
                          </a-select-option>
                          <a-select-option value="1">
                            已删除
                          </a-select-option>
                        </a-select>
                      </a-form-item>
                    </a-col>-->

          <a-col :md="4" :sm="12">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
<!--              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>-->
              <!--                <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>-->
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!--table区域-begin-->
    <div>
      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>

        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="30px" alt=""
               style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="uploadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a-menu-item v-if="record.status != 1" style="display: inline;margin-left: 10px">
                  <a-popconfirm title="确定删除吗?" @confirm="() => deleteFaFunc(record.id)">
                    <a style="color:deepskyblue">删除</a>
                  </a-popconfirm>
          </a-menu-item>
        </span>
      </a-table>
    </div>


    <!--新增发放的弹框-->
    <a-modal
      title="登记发放"
      v-model:visible="visible2"
      :confirm-loading="confirmLoading"
      @ok="addFaFunc"
    >
      <a-form>
        <a-form-item label="客户名称">
          <a-input @input="listCompanyFunc" style="width: 300px" v-model="haha" placeholder="请填写客户名称"></a-input>
        </a-form-item>

        <!--table区域-begin-->
        <div>
          <a-table
            size="middle"
            bordered
            rowKey="id"
            :columns="columns2"
            :dataSource="companyList"
            :pagination="false"
            :loading="loading"
            :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
            class="j-table-force-nowrap"
            @change="handleTableChange">

          </a-table>
        </div>

        <a-form-item label="商品册数量">
          <a-input-number :min="1" style="width: 300px" v-model="hehe"
                          placeholder="请输入商品册数量"></a-input-number>
        </a-form-item>

        <a-form-item label="备注信息">
          <a-input v-model="remark" type="textarea"
                   placeholder="请输入备注信息"></a-input>
        </a-form-item>
      </a-form>
    </a-modal>
    <!--编辑弹框结束-->

  </a-card>

</template>

<script>
import '@/assets/less/TableExpand.less'
import {mixinDevice} from '@/utils/mixin'
import {JeecgListMixin} from '@/mixins/JeecgListMixin'
import JDate from '@/components/jeecg/JDate.vue'
import {getAction} from "../../api/manage";
import {UploadOutlined} from '@ant-design/icons-vue';

export default {
  name: 'Fabric',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    JDate,
    UploadOutlined
    // LgyxCreditRateModal
  },
  data() {
    return {
      remark: '', // 备注信息
      companyList: [], // 公司列表
      haha: '',
      hehe: '',
      visible2: false, // 弹窗的显示
      bookdetail: {}, // 面料册信息
      visible: false, // 新增弹框的显示
      description: '面料订单',
      fabricOrderDetail: [], // 当前的面料订单详情
      fabricDetail: {}, // 面料详情
      orderDetail: {}, // 订单详情
      // 表头
      columns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '客户名称',
          align: "center",
          dataIndex: 'companyName'
        },
        {
          title: '客户编号',
          align: "center",
          dataIndex: 'companyCode'
          /* customRender: (text) => {
             //字典值替换通用方法
             return filterDictTextByCache('sex', text);
           }*/
        },
        {
          title: '客户电话',
          align: "center",
          dataIndex: 'aboutPhone'
        },
        {
          title: '发放数量',
          align: "center",
          dataIndex: 'number'
        },
        {
          title: '商品册单价(元/册)',
          align: "center",
          dataIndex: 'price'
        },
        {
          title: '商品册总价(元)',
          align: "center",
          dataIndex: 'allPrice'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          // fixed:"right",
          width: 147,
          scopedSlots: {customRender: 'action'}
        }
      ],
      // 发放的表头
      columns2: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '客户名称',
          align: "center",
          dataIndex: 'companyName'
        },
        {
          title: '联系电话',
          align: "center",
          dataIndex: 'aboutPhone'
        },
        {
          title: '地址',
          align: "center",
          dataIndex: 'address'
        }
      ],
      url: {
        list: '/goodsCenter/listFafang' + '?bookletid=' + this.$route.query.booklet, // 面料列表
        bookletDetail: "/goodsCenter/bookletDetail", // 面料册详情
        listCompany: "/fabricCenter/listCompany", // 公司列表
        addFa: "/goodsCenter/addFa", // 添加发放
        deleteFa: "/goodsCenter/deleteFa", // 删除发放
        exportFabric: "fabricCenter/exportFabric", // 导出Excel
      },
      dictOptions: {},
    }
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
    exportFabric: function () {
      return `${window._CONFIG['domianURL']}/${this.url.exportFabric}`
    }
  },
  created() {
    this.bookletDetailFunc()
    this.listCompanyFunc()
  },
  methods: {

    /**
     * 删除发放
     */
    deleteFaFunc(id) {
      getAction(this.url.deleteFa, {
        'id': id
      }).then(res => {
        if (res.code == 200) {
          this.$message.success("操作成功")
          this.loadData()
          this.bookletDetailFunc()
        }
      })
    },

    /**
     * 新增发放
     */
    addFaFunc() {
      // 非空验证
      if (this.hehe == '') {
        this.$message.warning("请输入发放数量")
        return
      } else if (this.selectedRowKeys.length == 0) {
        this.$message.warning("请选择发放客户")
        return
      } else {
        getAction(this.url.addFa, {
          'bookletid': this.$route.query.booklet, // 售后订单表ID
          'remark': this.remark,                // 备注
          'num': this.hehe, // 售后订单编号
          'companyids': this.selectedRowKeys.toString() // 选中的小产品ID
        }).then(res => {
          if (res.code == 200) {
            this.visible2 = false
            this.$message.success("操作成功")
            this.loadData()
            this.bookletDetailFunc()
          } else {
            this.$message.warning("商品册不足，无法发放")
          }
        })
      }
    },

    /**
     * 获取公司列表
     */
    listCompanyFunc() {
      getAction(this.url.listCompany, {
        'name': this.haha
      }).then(res => {
        if (res.code == 200) {
          this.companyList = res.result.records
        }
      })
    },

    /**
     * 发放弹窗
     */
    setyuejiewindow() {
      this.visible2 = true
    },

    /**
     * 获取详情
     */
    bookletDetailFunc() {
      getAction(this.url.bookletDetail, {'id': this.$route.query.booklet}).then(res => {
        if (res.code == '0') {
          this.bookdetail = res.data
        }
      })
    },

    initDictConfig() {
    }
  }
}
</script>

<style scoped>
@import '~@assets/less/common.less';

.fabricName {
  margin-left: 10px;
  margin-top: 10px;
  width: auto;
  display: block !important;
  background: #2d2d2d;
  color: #ffe56d;
  text-align: center;
  border-radius: 3px;
}

.fabigtitle {
  height: 34px;
  width: 200px;
  text-align: left;
}

.fabigcontent {
  height: 34px;
  width: 200px;
  text-align: right;
}

.fatitle {
  height: 34px;
  width: 82px;
  background: rgb(242 242 242);
  text-align: center;
}

.facontent {
  width: 180px;
  overflow: hidden;
  text-align: center;
}
</style>